{extend name="public/base"/}
{block name="body"}
<style type="text/css">
	.attrs{margin-top:5px;}
	.attrname{width:100px;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
	.attrval{width:40%;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
</style>
<title>添加产品</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="标题" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <div style="position:relative;" id="drop_area"></div>
                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:2:1</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">库存：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="number" class="input-text" value="" placeholder="0" id="num" name="num">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">所需积分：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="number" class="input-text" value="" placeholder="0" id="score" name="score">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">商品详情：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<script id="editor" name="detail" type="text/plain" style="width:100%;height:400px;"></script>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<!-- <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"> -->
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">

var imgpz;
$(function(){
	var ue = UE.getEditor('editor');
});
$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var title=$("input[name=title]").val();
	var score=$("input[name=score]").val();
	var num=$("input[name=num]").val();
	var detail=UE.getEditor('editor').getContent();
	$.ajax({
	    type: 'POST',
	    url: "{:url('goods_add')}",
	    data: {title:title,score:score,num:num,detail:detail,img:imgpz},
	    success: function(resdata){
	        if(resdata.code==200){
				layer.msg(resdata.msg,{icon:1,time:1000});
				setTimeout("parent.location.reload()",1000);
	        }else{
				layer.msg(resdata.msg,{icon:2,time:3000});
	        }
	    },
	    error: function(){
			layer.msg('数据保存失败',{icon:2,time:3000});
	    }
	})
});
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        var formData = new FormData();
	        formData.append("file",file);
	        $.ajax({
	              type: 'POST',
	              url: "{:url('uploadtmd')}",
	              data:formData,
	              contentType: false, /*不可缺*/
	              processData: false, /*不可缺*/
	              success: function(response){
	                if(response.code==200){
	                  imgpz=response.photo
	                }else{
	                  alert(response.msg);
	                }
	              },
	              error: function(err){

	              }
	        })
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
</script> 
{/block}